﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:AllowanceIssue
    /// </summary>
    public partial class AllowanceIssue
    {
        public AllowanceIssue()
        { }
        #region  BasicMethod

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(EnterpriseFund.Model.AllowanceIssue model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            var getBillIdSql = "exec sp_getbillno 'fund.t_AllowanceIssue','FIssueID','','','',@returnBId output ";
            var getBillIdPar = new SqlParameter[]{ 
                new SqlParameter("@returnBId", SqlDbType.NVarChar, 50)
            };

            getBillIdPar[0].Direction = ParameterDirection.Output;

            cmds.CommandText = getBillIdSql.ToString();
            cmds.Parameters = getBillIdPar;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("insert into fund.t_AllowanceIssue(");
            strSql.Append("FIssueID,FYear,FIssueNo,FAllowanceClassNo,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP)");
            strSql.Append(" values (");
            strSql.Append("@returnBId,@FYear,@FIssueNo,@FAllowanceClassNo,@FStatus,@FIsReturn,@FInsEmpNo,@FInsDeptNo,@FInsDate,@FInsIP,@FUpdEmplNo,@FUpdDeptNo,@FUpdDate,@FUpdIP)");
            SqlParameter[] parameters = {
					new SqlParameter("@returnBId", SqlDbType.NVarChar,50),
					new SqlParameter("@FYear", SqlDbType.Int,4),
					new SqlParameter("@FIssueNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FAllowanceClassNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInsDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15)};
            parameters[0].Direction = ParameterDirection.InputOutput;
            parameters[1].Value = model.FYear;
            parameters[2].Value = model.FIssueNo;
            parameters[3].Value = model.FAllowanceClassNo;
            parameters[4].Value = model.FStatus;
            parameters[5].Value = model.FIsReturn;
            parameters[6].Value = model.FInsEmpNo;
            parameters[7].Value = model.FInsDeptNo;
            parameters[8].Value = model.FInsDate;
            parameters[9].Value = model.FInsIP;
            parameters[10].Value = model.FUpdEmplNo;
            parameters[11].Value = model.FUpdDeptNo;
            parameters[12].Value = model.FUpdDate;
            parameters[13].Value = model.FUpdIP;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string FIssueID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from fund.t_AllowanceIssue ");
            strSql.Append(" where FIssueID=@FIssueID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FIssueID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string FIssueIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from fund.t_AllowanceIssue ");
            strSql.Append(" where FIssueID in (" + FIssueIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 确定旗号
        /// </summary>
        /// <param name="modelList"></param>
        /// <param name="issueID"></param>
        public void IssueAuditALL(string allowanceFileEntryID)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceIssueEntry set ");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FAllowanceIssueEntryID in (" + allowanceFileEntryID + ")  ");
            SqlParameter[] parameters2 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6)};
            parameters2[0].Value = "2";
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);


            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_SpecificAdjust set ");
            strSql.Append("FStatus=@FStatus ");
            strSql.Append(" where FSpecificAdjustNo  in (" + allowanceFileEntryID + ")   ");
            SqlParameter[] parameters4 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6)};
            parameters4[0].Value = "2";
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters4;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

          /// <summary>
        /// 确定旗号
        /// </summary>
        /// <param name="modelList"></param>
        /// <param name="issueID"></param>
        public void IssueAudit(string issueID)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceIssue set ");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FIssueID=@FIssueID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)};
            parameters[0].Value = "2";
            parameters[1].Value = issueID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceIssueEntry set ");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FIssueID=@FIssueID and FStatus='1' ");
            SqlParameter[] parameters2 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)};
            parameters2[0].Value = "2";
            parameters2[1].Value = issueID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

            /// <summary>
        /// 确定旗号
        /// </summary>
        /// <param name="modelList"></param>
        /// <param name="issueID"></param>
        public void IssueToOKPortion(List<Model.AllowanceIssueEntry> modelList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            foreach (Model.AllowanceIssueEntry model in modelList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("update fund.t_AllowanceIssueEntry set ");
                strSql.Append("FStatus=1 ,");
                strSql.Append("FFactAllowanceAmt=@FFactAllowanceAmt");
                strSql.Append(" where FIssueID=@FIssueID and FTaxClassAllowanceNo=@FTaxClassAllowanceNo and NSRDZDAH=@NSRDZDAH ");
                SqlParameter[] parameters4 = {
                    new SqlParameter("@FFactAllowanceAmt", SqlDbType.Decimal,32)	,	
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)	,	
                    new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)	,	
                    new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,20)	};
                parameters4[0].Value = model.FFactAllowanceAmt;
                parameters4[1].Value = model.FIssueID;
                parameters4[2].Value = model.FTaxClassAllowanceNo;
                parameters4[3].Value = model.NSRDZDAH;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters4;
                cmdList.Add(cmds);
            }


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }
        /// <summary>
        /// 确定旗号
        /// </summary>
        /// <param name="modelList"></param>
        /// <param name="issueID"></param>
        public void IssueToOK(string issueID,List<Model.AllowanceIssueEntry> modelList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceIssue set ");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FIssueID=@FIssueID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)};
            parameters[0].Value = "1";
            parameters[1].Value = issueID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            //cmds = new CommandInfo();
            //strSql = new StringBuilder();
            //strSql.Append("update fund.t_AllowanceIssueEntry  set ");
            //strSql.Append("FStatus='1'");
            //strSql.Append(" where FIssueID=@FIssueID and FStatus='0'");
            //SqlParameter[] parameters3 = {
            //        new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)};
            //parameters3[0].Value = issueID;
            //cmds.CommandText = strSql.ToString();
            //cmds.Parameters = parameters3;
            //cmdList.Add(cmds);

            foreach (Model.AllowanceIssueEntry model in modelList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("update fund.t_AllowanceIssueEntry set ");
                strSql.Append("FStatus=1 ,");
                strSql.Append("FFactAllowanceAmt=@FFactAllowanceAmt");
                strSql.Append(" where FIssueID=@FIssueID and FTaxClassAllowanceNo=@FTaxClassAllowanceNo and NSRDZDAH=@NSRDZDAH ");
                SqlParameter[] parameters3 = {
                    new SqlParameter("@FFactAllowanceAmt", SqlDbType.Decimal,32)	,	
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)	,	
                    new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)	,	
                    new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,20)	};
                parameters3[0].Value = model.FFactAllowanceAmt;
                parameters3[1].Value = model.FIssueID;
                parameters3[2].Value = model.FTaxClassAllowanceNo;
                parameters3[3].Value = model.NSRDZDAH;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters3;
                cmdList.Add(cmds);
            }



            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditPolicyEval set ");
            strSql.Append("FStatus=@FStatus ");
            strSql.Append(" where FIssueID=@FIssueID and FStatus<>9 ");
            SqlParameter[] parameters4 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
                    new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)};
            parameters4[0].Value = "3";
            parameters4[1].Value = issueID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters4;
            cmdList.Add(cmds);


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceIssue GetModelByFIssueNo(string FIssueNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FIssueID,FYear,FIssueNo,FAllowanceClassNo,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_AllowanceIssue ");
            strSql.Append(" where FStatus<>'3' and FIssueNo=@FIssueNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIssueNo", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FIssueNo;

            EnterpriseFund.Model.AllowanceIssue model = new EnterpriseFund.Model.AllowanceIssue();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体(FStatus<>'3')
        /// </summary>
        public EnterpriseFund.Model.AllowanceIssue GetModelByFIssueID(string FIssueID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FIssueID,FYear,FIssueNo,FAllowanceClassNo,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_AllowanceIssue ");
            strSql.Append(" where FStatus<>'3' and FIssueID=@FIssueID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FIssueID;

            EnterpriseFund.Model.AllowanceIssue model = new EnterpriseFund.Model.AllowanceIssue();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceIssue GetModelByIssueNo(string FIssueNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FIssueID,FYear,FIssueNo,FAllowanceClassNo,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_AllowanceIssue ");
            strSql.Append(" where FIssueNo=@FIssueNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIssueNo", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FIssueNo;

            EnterpriseFund.Model.AllowanceIssue model = new EnterpriseFund.Model.AllowanceIssue();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceIssue GetModel(string FIssueID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FIssueID,FYear,FIssueNo,FAllowanceClassNo,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_AllowanceIssue ");
            strSql.Append(" where FIssueID=@FIssueID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FIssueID;

            EnterpriseFund.Model.AllowanceIssue model = new EnterpriseFund.Model.AllowanceIssue();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceIssue GetLastModel()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"  SELECT TOP 1  FIssueID ,
                                            FYear ,
                                            FIssueNo ,
                                            FAllowanceClassNo ,
                                            FStatus ,
                                            FIsReturn ,
                                            FInsEmpNo ,
                                            FInsDeptNo ,
                                            FInsDate ,
                                            FInsIP ,
                                            FUpdEmplNo ,
                                            FUpdDeptNo ,
                                            FUpdDate ,
                                            FUpdIP FROM fund.t_AllowanceIssue where FStatus<>'2' ORDER BY FInsDate desc");

            EnterpriseFund.Model.AllowanceIssue model = new EnterpriseFund.Model.AllowanceIssue();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 获得当前年度的最大单号
        /// </summary>
        public string GetMaxNo(string allowanceClassNo,string year)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT MAX(FIssueNo) AS FIssueNo FROM fund.t_AllowanceIssue");
            strSql.Append(" where FAllowanceClassNo=@FAllowanceClassNo and FYear=@FYear ");
            SqlParameter[] parameters = {
					new SqlParameter("@FAllowanceClassNo", SqlDbType.NVarChar,6),
                    new SqlParameter("@FYear", SqlDbType.Int)				};
            parameters[0].Value = allowanceClassNo;
            parameters[1].Value = year;
            
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                return obj.ToString();
            }
            else
            {
                return "";
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceIssue DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.AllowanceIssue model = new EnterpriseFund.Model.AllowanceIssue();
            if (row != null)
            {
                if (row["FIssueID"] != null)
                {
                    model.FIssueID = row["FIssueID"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = int.Parse(row["FYear"].ToString());
                }
                if (row["FIssueNo"] != null)
                {
                    model.FIssueNo = row["FIssueNo"].ToString();
                }
                if (row["FAllowanceClassNo"] != null)
                {
                    model.FAllowanceClassNo = row["FAllowanceClassNo"].ToString();
                }
                if (row["FStatus"] != null)
                {
                    model.FStatus = row["FStatus"].ToString();
                }
                if (row["FIsReturn"] != null)
                {
                    model.FIsReturn = row["FIsReturn"].ToString();
                }
                if (row["FInsEmpNo"] != null)
                {
                    model.FInsEmpNo = row["FInsEmpNo"].ToString();
                }
                if (row["FInsDeptNo"] != null)
                {
                    model.FInsDeptNo = row["FInsDeptNo"].ToString();
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FUpdEmplNo"] != null)
                {
                    model.FUpdEmplNo = row["FUpdEmplNo"].ToString();
                }
                if (row["FUpdDeptNo"] != null)
                {
                    model.FUpdDeptNo = row["FUpdDeptNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
                if (row.Table.Columns.Contains("FAllowanceName"))
                {
                    if (row["FAllowanceName"] != null)
                    {
                        model.FAllowanceName = row["FAllowanceName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("nsrCounts"))
                {
                    if (row["nsrCounts"] != null && row["nsrCounts"].ToString() != "")
                    {
                        model.nsrCounts = int.Parse(row["nsrCounts"].ToString());
                    }
                }

            }

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FIssueID,FYear,FIssueNo,a.FAllowanceClassNo,b.FAllowanceName,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP ");
            strSql.Append(" FROM fund.t_AllowanceIssue a left join fund.t_AllowanceClass b on a.FAllowanceClassNo=b.FAllowanceClassNo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FIssueID,FYear,FIssueNo,FAllowanceClassNo,FStatus,FIsReturn,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP ");
            strSql.Append(" FROM fund.t_AllowanceIssue ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount2(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.v_AllowanceIssueCheckShow ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.v_AllowanceCalcManageShow ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FIssueID desc");
            }
            strSql.Append(")AS Row, T.*  from fund.t_AllowanceIssue T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_AllowanceIssue";
            parameters[1].Value = "FIssueID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

